//! $Id$
//!
//! @file    ContextCommit.h
//! @author  Johan Andersson <skagget77@gmail.com>
//! @date    Sat Oct 03 19:59 2009
//! @ingroup IoCppDetail

#if !defined(IOCPP_CONTEXTCOMMIT_H)
#define IOCPP_CONTEXTCOMMIT_H

namespace IoCpp
{
namespace Detail
{
   //!
   //! @author  Johan Andersson <skagget77@gmail.com>
   //! @date    Sat Oct 03 19:59 2009
   //! @ingroup IoCppDetail
   //!
   //! The ContextCommit class, a shared_ptr custom deleter that commits the
   //! managed context to the specified ResolverCache before deleting it.
   //!
   template<class T1>
   class ContextCommit
   {
   public :
      //!
      //! Creates a new instance of the ContextCommit class.
      //!
      //! @param cache The container's ResolverCache.
      //!
      ContextCommit( ResolverCache& cache );

      //!
      //! Commits the context to the container's ResolverCache.
      //!
      //! @param context The context to commit.
      //!
      void operator()( T1* context ) const;

   private :
      ResolverCache& cache;
   };


   template<class T1>
   ContextCommit<T1>::ContextCommit( ResolverCache& cache )
      : cache(cache) {
   }


   template<class T1>
   void ContextCommit<T1>::operator()( T1* context ) const 
   {
      context->Commit(cache);
      delete context;
   }
}
}

#endif   // IOCPP_CONTEXTCOMMIT_H
